package arrays

import "strings"

// JoinBy 将数组中的元素连接为一个字符串，使用回调函数来处理每个元素
func JoinBy[T any](array []T, separator string, fn func(T, int, []T) string) string {
	result := make([]string, 0, len(array))
	for i, v := range array {
		result = append(result, fn(v, i, array))
	}
	return strings.Join(result, separator)
}
